package com.hwadee.teachingprocessmanagementsystem.service.base.impl;

import com.hwadee.teachingprocessmanagementsystem.entity.ApplicationForm;
import com.hwadee.teachingprocessmanagementsystem.dao.ApplicationFormDao;
import com.hwadee.teachingprocessmanagementsystem.service.base.ApplicationFormService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import jakarta.annotation.Resource;

/**
 * 专升本报名表(ApplicationForm)表服务实现类
 *
 * @author makejava
 * @since 2024-07-11 14:20:02
 */
@Service("applicationFormService")
public class ApplicationFormServiceImpl implements ApplicationFormService {
    @Resource
    private ApplicationFormDao applicationFormDao;

    /**
     * 通过ID查询单条数据
     *
     * @param applicationId 主键
     * @return 实例对象
     */
    @Override
    public ApplicationForm queryById(Integer applicationId) {
        return this.applicationFormDao.queryById(applicationId);
    }

    /**
     * 分页查询
     *
     * @param applicationForm 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<ApplicationForm> queryByPage(ApplicationForm applicationForm, PageRequest pageRequest) {
        long total = this.applicationFormDao.count(applicationForm);
        return new PageImpl<>(this.applicationFormDao.queryAllByLimit(applicationForm, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param applicationForm 实例对象
     * @return 实例对象
     */
    @Override
    public ApplicationForm insert(ApplicationForm applicationForm) {
        this.applicationFormDao.insert(applicationForm);
        return applicationForm;
    }

    /**
     * 修改数据
     *
     * @param applicationForm 实例对象
     * @return 实例对象
     */
    @Override
    public ApplicationForm update(ApplicationForm applicationForm) {
        this.applicationFormDao.update(applicationForm);
        return this.queryById(applicationForm.getApplicationId());
    }

    /**
     * 通过主键删除数据
     *
     * @param applicationId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer applicationId) {
        return this.applicationFormDao.deleteById(applicationId) > 0;
    }
}
